package session;

import config.Configuration;
import executor.Executor;

import java.util.List;

public class SqlSessionImpl implements SqlSession{
    private SqlSession sqlSession;
    private Configuration config;
    public SqlSessionImpl(Configuration config) {
        this.config = config;
    }
    private SqlSession getSqlSession() {
        if (sqlSession == null) {
            sqlSession = new DefaultSqlSession<>(config);
        }
        return sqlSession;
    }

    @Override
    public int insert(String name, Object[] params) {
        return getSqlSession().insert(name, params);
    }

    @Override
    public int delete(String name, Object[] params) {
        return getSqlSession().delete(name, params);
    }

    @Override
    public int update(String name, Object[] params) {
        return getSqlSession().update(name, params);
    }

    @Override
    public <T> List<T> selectList(String name, Object[] args, Class<T> tClass) {
        return getSqlSession().selectList(name, args, tClass);
    }

    @Override
    public <T> T selectOne(String name, Object[] args, Class<T> tClass) {
        return getSqlSession().selectOne(name, args, tClass);
    }

    @Override
    public Configuration getConfiguration() {
        return getSqlSession().getConfiguration();
    }
}
